﻿using UnityEngine;
using System.Collections;
using DICE_GS;

public class UseSkillButton : uiBaseButton {
	
//	public int skillIndex;
	public int skillID;
	public int index;
	public bool isTempSkill;
	// Use this for initialization
	void Start () {
	
	}
	
	void OnClick()
	{
		CSkillData skillData = CSkillDataManager.Instance.FindSkillData(skillID);

		if(isTempSkill)
		{
			if( !UIManager.Instance.IsTempSkillCastOK(index) )
				return;
			glog.debug("use temp skill "+skillID+"  "+skillData.id);
			PC_OP_USE_TEMP_SKILL packet = new PC_OP_USE_TEMP_SKILL();
			packet.ServerID = BoardManager.Instance.boardPerson_me.SID;
			packet.TempSkillID = skillID;
			packet.TargetID = BoardManager.Instance.boardPerson_me.SID;
			if(BoardManager.Instance.boardPerson_me.pawnType != GAME_PAWN_TYPE.BOT)
				CNetworkManager.Instance.SendPacket(packet);
			else
				Debug.LogError("current BOT.  dont skill cast");
		}
		else
		{
			if( !UIManager.Instance.IsSkillCastOK( skillData, index) )
				return;

			PC_OP_USE_SKILL packet = new PC_OP_USE_SKILL();
			packet.ServerID = BoardManager.Instance.boardPerson_me.SID;
			packet.SkillID = skillID;
			if( skillData.target_type == target_type.Enemy_Select)
			{
				SkillManager.Instance.ReserveSkillToCast(packet);
				SkillManager.Instance.WaitSelectTarget(true);
				
			}
			else
			{
				glog.debug("use skill "+skillID+"  "+skillData.id);
				packet.TargetID = BoardManager.Instance.boardPerson_me.SID;
				//CNetworkManager.Instance.SendPacket(packet.Protocol, packet.GetParam());
				if(BoardManager.Instance.boardPerson_me.pawnType != GAME_PAWN_TYPE.BOT)
					CNetworkManager.Instance.SendPacket(packet);
				else
					Debug.LogError("current BOT.  dont skill cast");

			}		
		}
	}
	
//	void OnClick()
//	{
//		return;
//		if( MainHUDUI.Instance.skillBtn[skillIndex].isActive)
//		{
//			Camera.main.gameObject.GetComponent<CameraControl>().PressedUIButton(true);
//	        PC_OP_USE_SKILL packet = new PC_OP_USE_SKILL();
//	
//	        packet.ServerID = BoardManager.Instance.boardPerson_me.SID;
//			packet.SkillID = BoardManager.Instance.boardPerson_me.skillList[skillIndex].id;
//	
//	        CNetworkManager.Instance.SendPacket(packet.Protocol, packet.GetParam());	
//			
//			glog.debug ("send skill packet sid="+packet.ServerID+"  skillId="+packet.SkillID);
//			MainHUDUI.Instance.DecreaseMpBySkill(skillIndex);
//			//UIManager.Instance.bUseSkill = true;
//			UIManager.Instance.ShowMoveRollButton(false);
//			UIManager.Instance.CallDelayedPressUp();
//		}
//	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
